﻿Imports System.Data.OleDb
Imports DTO

Public Class LoaiDocGiaDAO

    Public Function LayDanhSach() As List(Of LoaiDocGiaDTO)
        Dim ds As New List(Of LoaiDocGiaDTO)
        Dim cn As OleDbConnection
        Dim strSQL As String
        'tao chuoi ket noi va mo ket noi bang doi tuong ket noi
        cn = DatabaseProvider.connectData()
        'tao chuoi  strSQL thao tac CSDL
        strSQL = "Select * From LoaiDocGia"
        'thuc thi chuoi strSQL
        Dim cmd As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        Dim ldg As LoaiDocGiaDTO
        While (dr.Read())
            ldg = New LoaiDocGiaDTO()
            'ldg.MaLoaiDocGia = dr("MaLoaiDocGia")
            'ldg.TenDocGia = dr ("TenDocGia")
            ldg.MaLoaiDocGia = dr.GetInt32(0)
            ldg.TenDocGia = dr.GetString(1)
            ds.Add(ldg)
        End While
        'Dong ket noi CSDL
        cn.Close()
        Return ds


    End Function

    Public Function TimKiem(ByVal maLoaiDocGia As Integer) As LoaiDocGiaDTO
        Dim ldgDTO As New LoaiDocGiaDTO()
        'Tao chuoi ket noi, mo kd\et noi bang doi tuong ket noi
        Dim cn As OleDbConnection
        cn = DatabaseProvider.connectData()
        Dim strSQL As String
        strSQL = "Select * From LoaiDocGia Where MaLoaiDocGia = ?"
        'thuc thi chuoi strSQL
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.Parameters.Add("@Ma", OleDbType.Integer)
        cmd.Parameters("@Ma").Value = maLoaiDocGia
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        While (dr.Read())
            ldgDTO.MaLoaiDocGia = dr("MaLoaiDocGia")
            ldgDTO.TenDocGia = dr("TenDocGia")
        End While
        'Dong ket noi CSDL
        dr.Close()
        cn.Close()
        Return ldgDTO
    End Function
End Class
